<template>
  <div class="StudentTable">
    <el-table :data="tableData" style="width: 100%;" :stripe="true">
      <!-- ID 列 -->
      <el-table-column label="ID" width="80">
        <template slot-scope="scope">
          {{ scope.row.id }}
        </template>
      </el-table-column>

      <!-- 最小抵扣积分 -->
      <el-table-column label="最小抵扣积分">
        <template slot-scope="scope">
          {{ scope.row.leastpoints }}
        </template>
      </el-table-column>
      


      <!-- 积分金额比例 -->
      <el-table-column label="积分金额比例">
        <template slot-scope="scope">
          {{ scope.row.leastPayMoney }}
        </template>
      </el-table-column>

      <!-- 积分使用门槛 -->
      <el-table-column label="积分使用门槛">
        <template slot-scope="scope">
          ￥{{ scope.row.leastPayMoney }}
        </template>
      </el-table-column>
      
      <!-- 佣金比例 -->
      <el-table-column label="佣金比例">
        <template slot-scope="scope">
          {{ scope.row.commissionProportion }}
        </template>
      </el-table-column>
      
            <!-- 购买后的积分比例 -->
      <el-table-column label="购买后的积分比例">
        <template slot-scope="scope">
          {{ scope.row.deductionMoney }}
        </template>
      </el-table-column>
            <!-- 最大使用积分 -->
      <el-table-column label="最大使用积分">
        <template slot-scope="scope">
          {{ scope.row.maxpoints }}
        </template>
      </el-table-column>

      <!-- 状态 -->
      <!-- <el-table-column label="状态" width="180">
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.state"
            :active-value="1"
            :inactive-value="0"
            active-text="使用中"
            inactive-text="已禁止"
            @change="handleStatusChange(scope.row)"
          ></el-switch>
        </template>
      </el-table-column> -->

      <!-- 操作列 -->
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button @click="handleEdit(scope.row)" type="primary" size="small">
            修改
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 修改弹窗表单 -->
    <el-dialog title="修改记录" :visible.sync="dialogVisible" width="600px">
      <el-form :model="editForm">
        <el-form-item label="最小抵扣积分">
          <el-input v-model="editForm.leastpoints"></el-input>
        </el-form-item>
   
        <el-form-item label="积分金额比例">
          <el-input v-model="editForm.leastPayMoney"></el-input>
        </el-form-item>
        <el-form-item label="积分使用门槛">
          <el-input v-model="editForm.leastPayMoney"></el-input>
        </el-form-item>
        <el-form-item label="佣金比例">
          <el-input v-model="editForm.commissionProportion"></el-input>
        </el-form-item>     
              <el-form-item label="购买后的积分比例">
          <el-input v-model="editForm.deductionMoney"></el-input>
        </el-form-item>
        <el-form-item label="最大积分使用">
          <el-input v-model="editForm.maxpoints"></el-input>
        </el-form-item>
      </el-form>

      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="handleSaveEdit">保存</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {getpointsset ,uppointsset} from '@/api/pcclinet'
export default {
  name: 'StudentTable',
  data() {
    return {
      dialogVisible: false, // 控制弹窗显示
      editForm: {}, // 用于存储当前编辑的表单数据
      currentRow: null, // 当前正在编辑的行
      // 静态数据
      tableData: [
      ]
    };
  },
  mounted(){
    this.getpointsset()
  },
  methods: {
    // 获取数据
    getpointsset(){
      getpointsset().then(res=>{
        //  console.log(res)
        this.tableData=res.data.pointssets
      })
    },
    // 状态修改处理
    handleStatusChange(row) {
      //  console.log(`状态已更改为: ${row.state === 1 ? '使用中' : '已禁止'}`);
    },
    // 处理修改操作，打开弹窗并将当前行数据传递给表单
    handleEdit(row) {
      this.currentRow = row; // 记录当前编辑的行
      this.editForm = { ...row }; // 深拷贝当前行数据到表单中
      this.dialogVisible = true; // 打开弹窗
    },
    // 保存修改
    handleSaveEdit() {
      Object.assign(this.currentRow, this.editForm); // 将编辑后的数据保存回当前行
      this.dialogVisible = false; // 关闭弹窗
      this.$message.success("修改成功");
      //  console.log(this.currentRow)
      this.uppointsset()
    },
    uppointsset(){
      uppointsset(this.currentRow).then(res=>{
        //  console.log(res)
      })
       }
  }
};
</script>

<style lang="scss" scoped>
.image-preview {
  max-width: 100px;
  max-height: 100px;
}
</style>
